#!/usr/bin/env bash

# ----------------------------------------------------------------------
# Filename	:  04-pagehighcache.sh
# Version	:  1.0
# Date		:  2025/02/07
# Author	:  yaoxiyao
# Email		:  yaoxiyao@kylinos.com.cn
# Function	:  GN-WJXT_012基于页的高速缓存
# Out		:
#              0 => TPASS
#              1 => TFAIL
#              other=> TCONF
# ----------------------------------------------------------------------

# 测试主题
Title_Env_LTFLIB="GN-WJXT_012基于页的高速缓存"

## TODO : 个性化,初始化
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestInit_LTFLIB() {
    return $TPASS
}

## TODO : 清理函数
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestClean_LTFLIB() {
    return $TPASS
}

## TODO : 测试用例集
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
Testsuite_LTFLIB() {
    testcase_1
    return $TPASS
}

## TODO ： GN-WJXT_005文件的访问
testcase_1() {
    local filesystem_src="../src/flush.c"
    gcc ${filesystem_src} -o flush
    CommRetParse_LTFLIB "gcc ${filesystem_src} -o flush"
    mv flush ${TmpTestDir_LTFLIB}
    CommRetParse_LTFLIB "mv flush ${TmpTestDir_LTFLIB}"
    cd ${TmpTestDir_LTFLIB}
    timeout 3s ./flush
    cat flushtest | grep C
    CommRetParse_LTFLIB "cat flushtest | grep C"
    rm -rf flushtest
    CommRetParse_LTFLIB "rm -rf flushtest"

    cd -
    sed -i 's/fflush(fp);/\/\/fflush(fp);/g' ${filesystem_src}
    CommRetParse_LTFLIB "sed -i 's/fflush(fp);/\/\/fflush(fp);/g' ${filesystem_src}"
    gcc ${filesystem_src} -o flush
    CommRetParse_LTFLIB "gcc ${filesystem_src} -o flush"
    mv flush ${TmpTestDir_LTFLIB}
    CommRetParse_LTFLIB "mv flush ${TmpTestDir_LTFLIB}"
    cd ${TmpTestDir_LTFLIB}
    timeout 3s ./flush
    ! cat flushtest | grep C
    CommRetParse_LTFLIB "! cat flushtest | grep C" "False"
    rm -rf flushtest
    CommRetParse_LTFLIB "rm -rf flushtest"

    cd -
    sed -i 's/\/\/fflush(fp);/fflush(fp);/g' ${filesystem_src}
    CommRetParse_LTFLIB "sed -i 's/\/\/fflush(fp);/fflush(fp);/g' ${filesystem_src}"
}
#----------------------------------------------#

source "${LIB_LTFLIB}"
Main_LTFLIB $@
